﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page language="java" import="com.wuliu.model.car.Car" %>
<%@ page language="java" import="com.wuliu.util.BaseUtil" %>
<%@ page language="java" import="com.wuliu.model.common.PageVO" %>
<%@ page language="java" import="com.wuliu.model.common.QueryVO" %>
<%@ page language="java" import="java.util.Map.Entry" %>  
<%
	String path = request.getContextPath();
	String flag = (String)request.getAttribute("flag");
    HashMap<String,String> hmSearch = (HashMap<String,String>)request.getAttribute("hmSearch"); 
	List<?> qList =  (List<?>)request.getAttribute("qList");
	if(qList==null)
		qList = new ArrayList();
%>
<!DOCTYPE html>
<html>
<head>
    <title>网豆物流平台-菜单管理</title>
    <link href="<%=path %>/web/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="<%=path %>/web/zTree_v3-master/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path %>/web/css/colorbox.css" rel="stylesheet" type="text/css"  />
    <link href="<%=path %>/web/css/style.css" rel="stylesheet" type="text/css"  />
    <script src="<%=path %>/web/js/jquery-1.11.1.min.js"></script>
    <script src="<%=path %>/web/js/jquery.colorbox-min.js"></script>
    <script src="<%=path %>/web/zTree_v3-master/js/jquery.ztree.core.js"></script>
    <script src="<%=path %>/web/zTree_v3-master/js/jquery.ztree.excheck.js"></script>
	<script src="<%=path %>/web/zTree_v3-master/js/jquery.ztree.exedit.js"></script>

    <script type="text/javascript">

	var path = "<%=path%>";
		
	//zTree参数设置
	var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
	};
    $(document).ready(function(){ 
		$("#add").colorbox({
			inline:true,
			width:"400px",
			close:"关闭",
			overlayClose:false  
		});
		$("#edit").colorbox({
			inline:true,
			width:"400px",
			close:"",
			overlayClose:false,
			onOpen:function(){    
			    var selId = getSelId();
			    if (selId==""){
					alert("请先选择一条数据！");
					$(this).colorbox.close();
					return;
				}
				$.ajax({
					type:"post",
					dataType:"json",
					url:path+"/CarAction!getCarInfo",
					data:{id:selId},
					success:function(data){  
					//alert(data);
						$("#carId").val(data.carId);	
						$("#carCode").val(data.carCode);	
						$("#workCode").val(data.workCode);
						$("#carType").val(data.carType);
						$("#carSize").val(data.carSize);
						$("#carTon").val(data.carTon);
						$("#buyDate").val(data.buyDate);
						$("#activeFlag").val(data.activeFlag);			 
					}
				});
			}
		});
		
	});

	function close_box(id){		   
		$("#"+id).colorbox.close();		
	}

	function  onSearch() {  
		 document.forms[0].action = "<%=path%>/CarAction!carList?flag=<%=flag%>";
		 document.forms[0].submit(); 
	}
	
	function  gotoPage(num) {  
		 document.forms[0].action = "<%=path%>/CarAction!carList?flag=<%=flag%>&pageNums="+num;
		 document.forms[0].submit(); 
	}
	
		//信息表单提交验证
	function checkForm(){
		if($("#carCode").val()==""){
			alert("车辆编码不能为空");
			$("#carCode").focus();
			return false;
		}
		if($("#workCode").val()==""){
			alert("运营证编号不能为空");
			$("#workCode").focus();
			return false;
		}
		return true;
	}
	function getSelId(){
	   var i=0;
	   var selId="";
	   $(":checkbox:checked").each(function(){  
	   	   i=i+1;
	       selId=$(this).val();  
	   });
	   if(i==0||i>1){
	   		return "";
	   }
	   return selId;
	} 
	
	function del(){
		var id = getSelId();	 
		if(id==""){
			alert("请选中要删除的信息");
		}else{
			if(confirm("您确定要删除选中信息，删除后不可恢复！")){ 
				document.forms[0].action = "<%=path%>/CarAction!delCar?id="+id; 
		    	document.forms[0].submit();  
			}
		}
	} 
	

	</script>
	<style type="text/css">
		table td{word-break: keep-all;white-space:nowrap;}
		table th{word-break: keep-all;white-space:nowrap;}
	</style>
	<script type="text/javascript">
		$(document).ready(function(){
			$(".table tr:even").addClass("active");
			
	        $(".table-margin tr").click(function(){
	        	$(".table tr").removeClass("success");
	        	$(".table tr:even").addClass("active");
	        	$(this).addClass("success");
	        });
		});
	</script>
</head>
<body>

    <div class="search-box row" style="padding-top:10px;border-bottom:1px solid #eee">  	
		<div class="col-md-12">			
	 		<div class="form-group">
		     	<span class="pull-left form-span">车辆编码：</span>
		    </div>
	     	<div class="form-group">
		     	<input type="text" name="s_car_code" id="s_car_code" placeholder="请输入车辆编码" class="form-control" value=""/>
	     	</div>
	     	<div class="form-group">
		     	<span class="pull-left form-span">运营证编码：</span>
		    </div>
	     	<div class="form-group">
		     	<input type="text" name="s_work_code" id="s_work_code" placeholder="请输入运营证编码" class="form-control" value=""/>
	     	</div>
  		 	 <div class="form-group btn-search">
	  		 	 <span></span>
	  		  	 <button class="btn btn-default" onclick="onSearch()" type="button" ><span class="glyphicon glyphicon-search"></span>查 询</button>
  		  	</div> 
		</div>
	</div>
	<div class="search-box row" style="padding-top:5px;">
		<div class="col-md-12">
	        <div class="btn-group pull-right" role="group" aria-label="...">
	        <%if(flag.equals("edit")){ %>
	  		  	 <a id="add" href="#ae_box"><button class="btn btn-default" type="button" ><span class="glyphicon glyphicon-search"></span>新 增</button></a>
	  		  	 <a id="edit" href="#ae_box"><button class="btn btn-default" type="button" ><span class="glyphicon glyphicon-search"></span>修 改</button></a>
	  			 <a id="del" href="#" onclick="del()"><button class="btn btn-default" type="button" ><span class="glyphicon glyphicon-search"></span>删 除</button></a>
	  		
	  		</div>
	  		<%} %>
	  	</div>
  	</div>
	<div class="clearfix"></div> 
		<div class="table-margin">
			<table class="table table-bordered table-header">
				<thead>
					<tr>
						<th>序号</th>
						<%
							for (int bi = 0; bi < qList.size(); bi++) {
									QueryVO vo = (QueryVO) qList.get(bi);
						%>
						<th><%=vo.getColName()%></th>
						<%
							}
						%>
					</tr>
				</thead>
				<tbody>
					<%
						PageVO pageVo = (PageVO) request.getAttribute("voResult");
							if (pageVo != null) {
								List<?> resultL = pageVo.getList();
								for (int ci = 0; ci < resultL.size(); ci++) {
					%>
					<tr align="center" onclick="setRowClass(this,'LT')">
						<td align="center"><%=ci + 1%></td>
						<%
							List<?> lDetail = (List<?>) resultL.get(ci);
										for (int si = 0; si < lDetail.size(); si++) {
						%>
						<td align="left"><%=(String) lDetail.get(si)%></td>
						<%
							}
						%>
					</tr>
					<%
						}
							}
					%>
				</tbody>
				<%
					if (pageVo != null) {
				%>
				<tfoot>
					<tr>
						<td colspan="17">
							<div class="pull-left">
								<nav>
								<ul class="pagination">
									<li><a href="#"
										onclick="gotoPage('<%=pageVo.getFirst_page()%>')"
										aria-label="首页"> <span aria-hidden="true">&laquo;</span>
									</a></li>
									<li><a href="#"
										onclick="gotoPage('<%=pageVo.getPrevious_page()%>')">前一页</a></li>
									<li><a href="#"
										onclick="gotoPage('<%=pageVo.getNext_page()%>')">下一页</a></li>
									<li><a href="#"
										onclick="gotoPage('<%=pageVo.getLast_page()%>')"
										aria-label="末页"> <span aria-hidden="true">&raquo;</span>
									</a></li>
									<li><a href="#">共<%=pageVo.getAll_size()%>条&nbsp;&nbsp;第<%=pageVo.getPresent_page()%>/<%=pageVo.getAll_page()%>页
									</a></li>
								</ul>
								</nav>
							</div>
						</td>
					</tr>
				</tfoot>
				<%
					}
				%>
			</table>
		</div>
		<div style="display:none;">
		   	<div id="ae_box">
		   	<form class="form-horizontal" method="post" onsubmit="return checkForm()" action="<%=path%>/CarAction!saveCar">   
		    	 <table class="table table-bordered table-header">
		    	 	<thead>  
			    	 	<tr>
				            <th colspan="6">维护车辆</th>               
					    </tr>
				    </thead>
				    <tbody>
				        <tr>
				        	<td align="right">
				            	车辆编码：
				            </td>
				            <td align="left">
				            	<input id="carCode" class='form-control' name="car.carCode" type="text" />
				            	<input id="carId" class='form-control' name="car.carId" type="hidden" />
				            </td> 
				        </tr>
				        <tr>
				            <td align="right">
				            	运营证编码：
				            </td>
				            <td align="left">
				            	<input id="workCode" class='form-control' name="car.workCode" type="text" />
				            </td>  
				        </tr>
				        <tr>
				            <td align="right">
				            	车辆类型
				            </td >
				            <td align="left">
				            	<input id="carType"  class='form-control' name="car.carType" type="text"  />
				            </td> 
				        </tr>
				        <tr>
				            <td align="right">
				            	车辆容积
				            </td >
				            <td align="left">
				            	<input id="carSize"  class='form-control' name="car.carSize" type="text"  />
				            </td> 
				        </tr>
				        <tr>
				            <td align="right">
				            	车辆重量：
				            </td>
							<td>
								<input id="carTon"  class='form-control' name="car.carTon" type="text"  />
							</td> 
				        </tr>
				        <tr>
				            <td align="right">
				            	购买日期：
				            </td>
							<td>
								<input id="buyDate"  class='form-control' name="car.buyDate" type="text"  />
							</td> 
				        </tr>
						<tr> 
							<td align="right">是否可用：</td>
							<td>
							     <select id="activeFlag" class='form-control' name="car.activeFlag" >  
									   <option value="">选择是否可用</option>
									   <option value="0">可用</option>
									   <option value="1">不可用</option>
								</select>
							</td> 
						</tr>
					</tbody>
					<tfoot>  
						<tr> 
							<td colspan="6" align="center">
							    <button class="btn btn-default" id="btnSave_edit" type="submit" ><span class="glyphicon glyphicon-ok"></span>保  存</button>
						 		<button class="btn btn-default" type="reset" onclick="close_box('add_box')" ><span class="glyphicon glyphicon-remove"></span> 取  消</button>
		          			</td> 
						</tr> 
					</tfoot>
				</table> 
		    	</form>
		   </div>
		</div>
		<div style="display:none;">
		   	<div id="auth_box">
		   		<form class="form-horizontal" method="post" onsubmit="return checkForm()" action="<%=path%>/CarAction!saveCar">   
					<table class="table table-bordered table-header">
			    	 	<thead>  
				    	 	<tr>
					            <th colspan="6">维护用户</th>               
						    </tr>
					    </thead>
					</table>
		    	 	<div>
                		<input type="hidden" name="carId" id="carIdForRole" />
						<ul id="roleTree" class="ztree"></ul>
	                </div>
	                <table class="table table-bordered table-header">
						<tfoot>  
							<tr> 
								<td colspan="6" align="center">
								    <button class="btn btn-default" id="btnSave_auth" onclick="auth()" type="button" ><span class="glyphicon glyphicon-ok"></span>保  存</button>
							 		<button class="btn btn-default" type="reset" onclick="close_box('auth_box')" ><span class="glyphicon glyphicon-remove"></span> 取  消</button>
			          			</td> 
							</tr> 
						</tfoot>
					</table>
		    	</form>
		   </div>
		</div>
 <script type="text/javascript">
     var showMsg='<%=request.getAttribute("showMsg")%>';
     if(showMsg!="null"&&showMsg!=""){
        alert(showMsg);
     } 
    <%
    if(hmSearch!=null){
    Iterator iter = hmSearch.entrySet().iterator(); 
	while (iter.hasNext()) { 
	Entry entry = (Entry) iter.next();  
	if(!((String)entry.getValue()).equals("")){
	%>  
    document.all.<%=(String)entry.getKey()%>.value = "<%=(String)entry.getValue()%>"; 
	<%
	}}}
     %>
</script>
</body>
</html>
